
// 存放所有的filter函数
// @date:2024-02-20 @author:wangff8@qq.com
library InitFilter

    // 匹配敌对单位
    // 匹配单位是友军的敌对单位   匹配单位的生命值>0 不能有无敌
    // 使用位置，英雄被动QWER技能，其他位置的发现在记录
    function heroSkillConditions takes nothing returns boolean
        return ((IsUnitEnemy(GetFilterUnit(), Player(4))) and (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0) and (GetUnitAbilityLevel(GetFilterUnit(), 'Avul') == 0))
    endfunction

    // 触发单位是英雄
    function heroTriConditions takes nothing returns boolean
        return ((GetTriggerUnit() == udg_player_select_hero[0]) or (GetTriggerUnit() == udg_player_select_hero[1]) or (GetTriggerUnit() == udg_player_select_hero[2]) or (GetTriggerUnit() == udg_player_select_hero[3]))
    endfunction

    // 凶手单位是英雄
    function enemyDieConditions takes nothing returns boolean
        local integer uid = 0
        local boolean retVal = false
        // 伤害来源必须是英雄
        // 命运 - 双子双生 - 也继承英雄伤害
        loop
            exitwhen uid > PLAYER_NUMBER
            if GetUnitTypeId(GetKillingUnit()) == GetUnitTypeId(udg_player_select_hero[uid]) then
                set retVal = true
            endif
            set uid = uid + 1
        endloop

        return retVal
        // return (((GetKillingUnit() == udg_player_select_hero[0]) or (GetKillingUnit() == udg_player_select_hero[1]) or (GetKillingUnit() == udg_player_select_hero[2]) or (GetKillingUnit() == udg_player_select_hero[3])))
    endfunction

    // ============================ 怪物受到伤害处理
    function guiawuTriConditions takes nothing returns boolean
        local integer uid = 0
        local boolean retVal = false
        local integer sourceTypeId = GetUnitTypeId(GetEventDamageSource())
        // 伤害来源必须是英雄
        loop
            exitwhen uid > PLAYER_NUMBER
            if sourceTypeId == GetUnitTypeId(udg_player_select_hero[uid]) then
                set retVal = true
            endif
            set uid = uid + 1
        endloop

        return retVal or sourceTypeId == 'N002'
        // return ((GetEventDamageSource() == udg_player_select_hero[0]) or (GetEventDamageSource() == udg_player_select_hero[1]) or (GetEventDamageSource() == udg_player_select_hero[2]) or (GetEventDamageSource() == udg_player_select_hero[3]))
    endfunction

endlibrary
